import * as types from './mutation-types'

const mutations = {
	[types.TOKEN](state, info) {
		state.token = info
	},
	[types.SET_TABLIST](state, list) {
		let tabs = state.tabList
		state.tabList.push(list)
		var hash = {};
		state.tabList = tabs.reduce(function(item, next) {
			hash[next.name] ? '' : hash[next.name] = true && item.push(next);
			return item
		}, [])
	},
	[types.NAV](state, list) {
		let tabs = [];
		tabs.push(list)
		state.nav.push(list)
		var hash = {};
		state.nav = tabs.reduce(function(item, next) {
			hash[next.name] ? '' : hash[next.name] = true && item.push(next);
			return item
		}, [])
	},
	[types.PURL](state, list) {
		let tabs = state.purl
		state.purl.push(list)
		var hash = {};
		state.purl = tabs.reduce(function(item, next) {
			hash[next.name] ? '' : hash[next.name] = true && item.push(next);
			return item
		}, [])
	},
	[types.DELETE_TABLIST](state, {
		index,
		length
	}) {
		state.tabList.splice(index, length)
	}

}

export default mutations